
template<class T> 
typename remove_reference<T>::type&&
std::move(T&& a)
{
  typedef typename remove_reference<T>::type&& RvalRef;
  return static_cast<RvalRef>(a);
} 


template<class _Ty>
 constexpr _Ty&& forward(remove_reference<_Ty>& _Arg)
	{	// forward an lvalue as either an lvalue or an rvalue
	return (static_cast<_Ty&&>(_Arg));
	}

template<class _Ty>
 constexpr _Ty&& forward(remove_reference<_Ty>&& _Arg)  //这里重载的原因是要得知_Ty是左值还是右值
	{	// forward an lvalue as either an lvalue or an rvalue
	return (static_cast<_Ty&&>(_Arg));
	}





template<class T>
class shared_ptr
{

public:
	shared_ptr():ptr(nullptr),count(nullptr)
	{
	}

	explicit shared_ptr(T *t) :ptr(t), count(nullptr)
	{
		if (ptr)
		{
			count = new int(1);
		}
	}
	// copy constructor
	explicit shared_ptr(const shared_ptr<T> & res)
	{
		ptr= res.ptr;
		count = res.count;
		if (count)
		{
			(*count)++;
		}
	}

	shared_ptr &operator=(const shared_ptr<T> &res)
	{
		if (this == &res)
		{
			return *this;
		}
		reset();
		ptr = res->ptr;
		count = res->count;
		if (count)
		{
			(*count)++;
		}
		return *this;
	}

	~shared_ptr()
	{
		reset();
	}

	void reset()
	{
		if (count)
		{
			(*count)--;
			if (*count == 0)
			{
				delete ptr;
				delete count;
			}
		}

	}
private:
	T *ptr;
	int *count;
};
